package com.sx.netty.nio;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.channels.FileChannel;

/**
 * @Author Administrator
 * @Description
 * @Date 2020/11/2 17:02
 *
 * 实现：文件的拷贝
 */
public class NIOFileChannel04 {
    public static void main(String[] args) throws Exception{
        FileInputStream fileInputStream = new FileInputStream("d://file.txt");
        FileOutputStream fileOutputStream = new FileOutputStream("d://file03.txt");

        FileChannel channel01 = fileInputStream.getChannel();
        FileChannel channel02 = fileOutputStream.getChannel();

//        使用transfer完成拷贝
        channel02.transferFrom(channel01,0,channel01.size());

//        关闭相应的流
        fileInputStream.close();
        fileOutputStream.close();
    }
}
